/*
* $Id: SyncWizard.cpp 340 2011-10-20 08:08:01Z volok-aleksej@yandex.ru $
*
* Copyright 2009-2011 by Volokitin Aleksey
* All rights reserved
*
*/
#include "Common/include.h"
#include "SyncWizard.h"
#include "LanguageManager.h"
#include "Wizard/SyncStart.h"

#define SYNC_TIMER_ID 1

CSyncWizard::CSyncWizard()
: CDialog(IDD_WIZARD), m_pStep(NULL){
	m_pFirstStep = new CSyncStart(this);
	m_pStep = m_pFirstStep;
}

CSyncWizard::~CSyncWizard(){
	if(m_pFirstStep)
		delete m_pFirstStep;
}

BOOL CSyncWizard::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
	if(m_pStep && m_pStep->MessageHandler(message, (unsigned int)wParam, (long)lParam, pResult))
		return TRUE;
	else
		return __super::OnWndMsg(message, wParam, lParam, pResult);
}

BOOL CSyncWizard::OnInitDialog(){
	BOOL bInit = __super::OnInitDialog();
	SetFocus();
	SetTimer(SYNC_TIMER_ID, 500, NULL);
	SetWindowText(CLanguageManager::GetLanguageManager()->GetString(SYNC_ID).c_str());
	m_cancelButton.SetWindowText(CLanguageManager::GetLanguageManager()->GetString(CANCEL_ID).c_str());
	m_nextButton.SetWindowText(CLanguageManager::GetLanguageManager()->GetString(NEXT_ID).c_str());
	m_backButton.SetWindowText(CLanguageManager::GetLanguageManager()->GetString(BACK_ID).c_str());
	if(m_pStep)
		m_pStep->Init(CPoint(0, 100));
	return bInit;
}

void CSyncWizard::DoDataExchange(CDataExchange* pDX){
	__super::DoDataExchange(pDX);
	DDX_Control(pDX, ID_NEXT, m_nextButton);
	DDX_Control(pDX, ID_BACK, m_backButton);
	DDX_Control(pDX, IDCANCEL, m_cancelButton);
}

void CSyncWizard::OnCancel(){
	KillTimer(SYNC_TIMER_ID);
	EndDialog(0);
}

BEGIN_MESSAGE_MAP(CSyncWizard, CDialog)
	ON_COMMAND(ID_NEXT, OnNext)
	ON_COMMAND(ID_BACK, OnBack)
	ON_WM_TIMER()
END_MESSAGE_MAP()

void CSyncWizard::OnNext(){
	if(!m_pStep)
		return;
	m_pStep = m_pStep->Next();
	if(!m_pStep)
		OnCancel();
	else
		m_pStep->Init(CPoint(0, 100));
}

void CSyncWizard::OnBack(){
	if(!m_pStep)
		return;
	m_pStep = m_pStep->Back();
	if(m_pStep)
		m_pStep->Init(CPoint(0, 100));
}

void CSyncWizard::OnTimer(UINT_PTR nIDEvent)
{
	if(!m_pStep)
		return;
	m_pStep->Update();
}